if [ -n "$1" ]; then
    data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi

dws_hour_common_ads_agg="
INSERT OVERWRITE TABLE jtp_app_warehouse.dws_hour_common_ads_agg PARTITION (dt = '${data_date}')
SELECT
    hour(from_unixtime(event_time/1000)) AS hr
    ,ad_id
    ,ad_name
    ,platform_id
    ,platform_alias_zh
    ,client_province
    ,client_city
    ,client_os_type
    ,client_browser_version
    ,is_invalid_traffic
    ,count(if(event_type='click',ad_id,NULL)) AS click_count
    ,count(ad_id) AS impression_count
FROM jtp_app_warehouse.dwd_ads_event_log_full
WHERE dt = '${data_date}'
AND event_type IN ('click','impression')
GROUP BY hr,ad_id,ad_name,platform_id,platform_alias_zh,client_province,client_city,client_os_type,client_browser_version,is_invalid_traffic;
"
/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "
${dws_hour_common_ads_agg}
"